home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / TGCBOR20.ARJ / INTROPAK.COM / PCXDEMO.C < prev    next >
C/C++ Source or Header  |  1991-08-28  |  8KB  |  379 lines

  1.  
  2. #include <teglsys.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <conio.h>
  6. #include "pcxdemo.inc"
  7.  
  8. int ix1,iy1,ix2,iy2;
  9.  
  10. /* NOTE! when linking you must also specify the lips2.obj file */
  11.  
  12. void cdecl lipspcxproc(void);
  13.  
  14. unsigned char userpressingbutton(imagestkptr fs,msclickptr ms)
  15. {
  16.     unsigned mxpos,mypos;
  17.     unsigned stat;
  18.     msclickptr ms1;
  19.  
  20.     stat = mouseposition(&mxpos,&mypos);
  21.  
  22.     if (functionkeycode == 0)
  23.     ms1 = checkmouseclickpos(fs,mxpos,mypos);
  24.     else {
  25.     stat = scancodetable[functionkeycode & 0x00ff];
  26.     ms1 = ms;
  27.     }
  28.  
  29.     return (ms1 == ms) && (stat != 0);
  30. }
  31.  
  32. unsigned viewsecondscreen(imagestkptr ifs,msclickptr ms)
  33. {
  34.     int ax,ay;
  35.  
  36.     hidemouse();
  37.  
  38.     ax = ms->ms.x & 0xfff8;
  39.     ay = ms->ms.y;
  40.  
  41.     movestackimage(ifs,ax,ay);
  42.  
  43.     showmouse();
  44.     return 1;
  45. }
  46.  
  47. unsigned bouncedemo(imagestkptr ifs,msclickptr ms)
  48. {
  49.     unsigned char d,e,r;
  50.     int x,y,ct;
  51.  
  52.     if (visualsquarebuttonpress(ifs,ms)) {
  53.     hidemouse();
  54.     x = ifs->x + 16;
  55.     y = ifs->y + 16;
  56.  
  57.     ix1 = ix1 & 0xfff8;
  58.     ix2 = ix1 + 368;
  59.  
  60.     while (kbhit())
  61.         getch();
  62.  
  63.     d = TRUE;
  64.     e = TRUE;
  65.     r = TRUE;
  66.     ct = 1;
  67.     do {
  68.         if (d) {
  69.         while ((iy2 < 338) && (!kbhit()) && (!mouse_buttons)) {
  70.             movevideopixels(ix1,iy1,ix2,iy2,x,y,0,0,TGMK_FP(0xa000,0x9600),TGMK_FP(0xa000,0x0000));
  71.             iy1 += ct;
  72.             iy2 += ct;
  73.         }
  74.  
  75.         if (iy2 > 338) {
  76.             iy1 -= ct;
  77.             iy2 -= ct;
  78.         }
  79.         } else {
  80.         while ((iy1 > 0) && (!kbhit()) && (!mouse_buttons)) {
  81.             movevideopixels(ix1,iy1,ix2,iy2,x,y,0,0,TGMK_FP(0xa000,0x9600),TGMK_FP(0xa000,0x0000));
  82.             iy1 -= ct;
  83.             iy2 -= ct;
  84.         }
  85.  
  86.         if (iy1 < 0) {
  87.             iy1 += ct;
  88.             iy2 += ct;
  89.         }
  90.         }
  91.  
  92.         d = !d;
  93.  
  94.         if (e) {
  95.         ix1 += 8;
  96.         ix2 += 8;
  97.         } else {
  98.         ix1 -= 8;
  99.         ix2 -= 8;
  100.         }
  101.  
  102.         if (ix2 > 639) {
  103.         ix1 -= 8;
  104.         ix2 -= 8;
  105.         e = !e;
  106.         } else if (ix1 < 0) {
  107.         ix1 += 8;
  108.         ix2 += 8;
  109.         e = !e;
  110.         }
  111.         if (r) {
  112.         ct++;
  113.         if (ct > 10)
  114.             r = !r;
  115.         } else {
  116.         ct--;
  117.         if (ct == 1)
  118.             r = !r;
  119.         }
  120.     } while (!((kbhit()) || (mouse_buttons)));
  121.  
  122.     showmouse();
  123.     while (kbhit())
  124.         getch();
  125.  
  126.     while (mouse_buttons) {}
  127.  
  128.     releasesquarebutton(ifs,ms);
  129.     }
  130.     return 1;
  131. }
  132.  
  133. unsigned shiftvert(imagestkptr ifs,msclickptr ms)
  134. {
  135.     int x,y,x1,y1;
  136.  
  137.     presssquarebutton(ifs,ms);
  138.  
  139.     x = ifs->x + 16;
  140.     y = ifs->y + 16;
  141.     x1 = x + 368 + 16;
  142.     y1 = y + 168 + 16;
  143.  
  144.     prepareforpartialupdate(ifs,x,y,x1,y1);
  145.     do {
  146.     switch (ms->clicknumber) {
  147.  
  148. /* /\ */case 7:{
  149.         iy1 -= 8;
  150.         iy2 -= 8;
  151.         }
  152.         break;
  153.  
  154. /* \/ */case 8:{
  155.         iy1--;
  156.         iy2--;
  157.         }
  158.         break;
  159.  
  160. /* /\ */case 9:{
  161.         iy1++;
  162.         iy2++;
  163.         }
  164.         break;
  165.  
  166.     case 10:{
  167.         iy1 += 8;
  168.         iy2 += 8;
  169.         }
  170.         break;
  171.     }
  172.  
  173.     if (iy1 < 0) {
  174.         iy1 = 0;
  175.         iy2 = 168;
  176.     } else if (iy2 > 338) {
  177.         iy1 = 338 - (iy2 - iy1);
  178.         iy2 = 338;
  179.     }
  180.     movevideopixels(ix1,iy1,ix2,iy2,x,y,0,0,TGMK_FP(0xa000,0x9600),TGMK_FP(0xa000,0x0000));
  181.     } while (userpressingbutton(ifs,ms));
  182.     commitupdate();
  183.     releasesquarebutton(ifs,ms);
  184.  
  185.     return 1;
  186. }
  187.  
  188. unsigned scrollhorz(imagestkptr ifs,msclickptr ms)
  189. {
  190.     int x,y,x1,y1;
  191.  
  192.     presssquarebutton(ifs,ms);
  193.  
  194.     x = ifs->x + 16;
  195.     y = ifs->y + 16;
  196.     x1 = x + 368;
  197.     y1 = y + 168;
  198.  
  199.     prepareforpartialupdate(ifs,x,y,x1,y1);
  200.     do {
  201.     switch (ms->clicknumber) {
  202.  
  203. /* .< */case 11:
  204.         movevideopixels(x,y,x1,y1,x,y,0,8,TGMK_FP(0xa000,0x0000),TGMK_FP(0xa000,0x0000));
  205.         break;
  206.  
  207. /* .> */case 13:
  208.         movevideopixels(x,y,x1,y1,x,y,0,-8,TGMK_FP(0xa000,0x0000),TGMK_FP(0xa000,0x0000));
  209.         break;
  210.     }
  211.     } while (userpressingbutton(ifs,ms));
  212.     commitupdate();
  213.     releasesquarebutton(ifs,ms);
  214.  
  215.     return 1;
  216. }
  217.  
  218.  
  219. unsigned scrollvert(imagestkptr ifs,msclickptr ms)
  220. {
  221.     int x,y,x1,y1;
  222.  
  223.     presssquarebutton(ifs,ms);
  224.  
  225.     x = ifs->x + 16;
  226.     y = ifs->y + 16;
  227.     x1 = x + 368;
  228.     y1 = y + 168;
  229.  
  230.     prepareforpartialupdate(ifs,x,y,x1,y1);
  231.     do {
  232.     switch (ms->clicknumber) {
  233.  
  234. /* .^ */case 12:
  235.         movevideopixels(x,y,x1,y1,x,y,-8,0,TGMK_FP(0xa000,0x0000),TGMK_FP(0xa000,0x0000));
  236.         break;
  237.  
  238. /* .v */case 14:
  239.         movevideopixels(x,y,x1,y1,x,y,8,0,TGMK_FP(0xa000,0x0000),TGMK_FP(0xa000,0x0000));
  240.         break;
  241.     }
  242.     } while (userpressingbutton(ifs,ms));
  243.     commitupdate();
  244.     releasesquarebutton(ifs,ms);
  245.  
  246.     return 1;
  247. }
  248.  
  249. unsigned shifthorz(imagestkptr ifs,msclickptr ms)
  250. {
  251.     int x,y,x1,y1;
  252.  
  253.     presssquarebutton(ifs,ms);
  254.  
  255.     x = ifs->x + 16;
  256.     y = ifs->y + 16;
  257.     x1 = x + 368;
  258.     y1 = y + 168;
  259.  
  260.     prepareforpartialupdate(ifs,x,y,x1,y1);
  261.     do {
  262.     switch (ms->clicknumber) {
  263.  
  264. /* << */case 3:{
  265.         ix1 -= 8;
  266.         ix2 -= 8;
  267.         ix2 = ix2 - (ix1 & 7);
  268.         ix1 = ix1 & 0xfff8;
  269.         }
  270.         break;
  271.  
  272. /* < */ case 4:{
  273.         ix1--;
  274.         ix2--;
  275.         }
  276.         break;
  277.  
  278. /* > */ case 5:{
  279.         ix1++;
  280.         ix2++;
  281.         }
  282.         break;
  283.  
  284. /* >> */case 6:{
  285.         ix1 += 8;
  286.         ix2 += 8;
  287.         ix2 = ix2 - (ix1 & 7);
  288.         ix1 = ix1 & 0xfff8;
  289.         }
  290.         break;
  291.     }
  292.  
  293.     if (ix1 < 0) {
  294.         ix1 = 0;
  295.         ix2 = 368;
  296.     } else if (ix2 > 639) {
  297.         ix1 = 639 - (ix2 - ix1);
  298.         ix2 = 639;
  299.     }
  300.     movevideopixels(ix1,iy1,ix2,iy2,x,y,0,0,TGMK_FP(0xa000,0x9600),TGMK_FP(0xa000,0x0000));
  301.  
  302.     } while (userpressingbutton(ifs,ms));
  303.     commitupdate();
  304.     releasesquarebutton(ifs,ms);
  305.  
  306.     return 1;
  307. }
  308.  
  309. unsigned exitoption(imagestkptr ifs,msclickptr ms)
  310. {
  311.     if (visualsquarebuttonpress(ifs,ms))
  312.     abortexit("TEGL PCX Graphics DEMO");
  313.     return 1;
  314. }
  315.  
  316. void main(void)
  317. {
  318.     maxwindowsize = 128000;
  319.     setvideochoices(TG_CGA,FALSE);
  320.     setvideochoices(TG_HGC,FALSE);
  321.     setvideochoices(TG_EGA,FALSE);
  322.     registertgidriver(GREVGA16_driver);
  323.  
  324.     setstandardheapsize(64000L);/* Reserve about 32k for Video Drivers */
  325.     teglinit(videoautodetect(),20480);
  326.  
  327.     quickshowpcxfile("TEGLLOGO.PCX",TRUE,0,getmaxy(),getmaxx());
  328.     ippushimage(0,0,319,239);
  329.  
  330.     if (getmaxy() > 400) {
  331.     ipputimage(320,0,ipstack,FGNORM);
  332.     ipputimage(0,240,ipstack,FGNORM);
  333.     ipsetcoord(ipstack,320,240,639,479);
  334.     } else
  335.     ipsetcoord(ipstack,320,108,639,347);
  336.     ippopimage();
  337.  
  338.     setpcxbwmap(0xff,0xff,0xff,0xff);
  339.     /* there are only 27k bytes left on the second portion of the VGA */
  340.     /* thus you can get only about 338 lines. */
  341.     displaypcxfile(lipspcxproc,TRUE,0x9600,338,getmaxx());
  342.  
  343.     setpalette(DARKGRAY,48);
  344.     pushimage(80,100,480,325);
  345.     bevelboxfs(stackptr,0,0,400,225,WHITE,LIGHTGRAY,LIGHTGRAY,8);
  346.     bevelboxfs(stackptr,8,8,392,192,LIGHTGRAY,WHITE,LIGHTGRAY,7);
  347.     setmoveframecallproc(stackptr,viewsecondscreen);
  348.     movevideopixels(96,96,464,264,96,116,0,0,TGMK_FP(0xa000,0x9600),TGMK_FP(0xa000,0x0000));
  349.  
  350.     ix1 = 96;
  351.     iy1 = 96;
  352.     ix2 = 464;
  353.     iy2 = 264;
  354.  
  355.  
  356.     definesquarebuttontext(stackptr,8,192,57,217,10,4,"QUIT",exitoption);
  357.     definesquarebuttontext(stackptr,57,192,110,217,12,4,"DEMO",bouncedemo);
  358.  
  359.     definesquarebuttonclick(stackptr,110,192,140,217,4,7,imageSHFTLL,shifthorz);
  360.     definesquarebuttonclick(stackptr,140,192,170,217,4,7,imageSHFTL,shifthorz);
  361.     definesquarebuttonclick(stackptr,170,192,200,217,4,7,imageSHFTR,shifthorz);
  362.     definesquarebuttonclick(stackptr,200,192,230,217,4,7,imageSHFTRR,shifthorz);
  363.  
  364.     definesquarebuttonclick(stackptr,230,192,260,217,4,7,imageSHFTUU,shiftvert);
  365.     definesquarebuttonclick(stackptr,260,192,290,217,4,7,imageSHFTU,shiftvert);
  366.     definesquarebuttonclick(stackptr,290,192,320,217,4,7,imageSHFTD,shiftvert);
  367.     definesquarebuttonclick(stackptr,320,192,350,217,4,7,imageSHFTDD,shiftvert);
  368.  
  369.     definesquarebuttonclick(stackptr,350,192,371,205,7,3,imageTSHFTL,scrollhorz);
  370.     definesquarebuttonclick(stackptr,350,205,371,217,7,3,imageTSHFTU,scrollvert);
  371.  
  372.     definesquarebuttonclick(stackptr,371,192,392,205,7,3,imageTSHFTR,scrollhorz);
  373.     definesquarebuttonclick(stackptr,371,205,392,217,7,3,imageTSHFTD,scrollvert);
  374.  
  375.     setctrlbreakfs(exitoption);
  376.  
  377.     teglsupervisor();
  378. }
  379.